package cn.itzzx.lagou.blog.controller;

import cn.itzzx.lagou.blog.pojo.Article;
import cn.itzzx.lagou.blog.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * TODO
 *
 * @author Martin
 * @since 1.0
 */
@Controller
public class BlogController {

    @Autowired
    private ArticleService articleService;

    /**
     * @param page 当前页
     * @param rows 每页大小
     * @return
     */
    @RequestMapping("index")
    public ModelAndView index(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                              @RequestParam(value = "rows", required = false, defaultValue = "3") Integer rows) {
        PageInfo<Article> pageInfo = articleService.listArticle(page, rows);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/client/index");
        modelAndView.addObject("pageInfo", pageInfo);
        return modelAndView;
    }
}
